package cn.hairui.blog.mapper;

import cn.hairui.blog.model.Topic;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;
import java.util.Map;

/**
 * @author lihairui
 * @version V1.0
 * @date: 2019/7/28 22:04
 */
@Mapper
public interface TopicMapper extends BaseMapper<Topic> {

    @Select("SELECT * FROM TOPIC LIMIT 0,#{count}")
    List<Topic> findLimited(int count);

    @Select("SELECT * FROM TOPIC ORDER BY ID DESC")
    List<Topic> list();

    @Select("SELECT T1.ID id, T1.TOPIC_NAME topicName, (SELECT COUNT(1) FROM ARTICAL T2 WHERE T1.ID=T2.TOPICID) AS articalNum FROM TOPIC T1 ORDER BY T1.ID ASC")
    List<Map> listMgr();

    @Select("SELECT A.ID AS topicId,A.TOPIC_NAME AS topicName,(SELECT COUNT(1) FROM ARTICAL B WHERE A.ID=B.TOPICID) AS topicNum FROM TOPIC A")
    List<Map> findCountList();
}
